import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEAction } from '../action/ipsdeaction';
import { IPSDEMainState } from './ipsdemain-state';
import { IPSDEMainStateAction } from './ipsdemain-state-action';
import { IPSDEMainStateField } from './ipsdemain-state-field';
import { IPSDEMainStateOPPriv } from './ipsdemain-state-oppriv';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEMainStateImpl extends PSModelObjectImpl implements IPSDEMainState, IPSModelSortable {
  get actionDenyMsg(): string {
    return this.M.actionDenyMsg;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  protected enterpsdeaction: IPSDEAction | null = null;

  getEnterPSDEAction(): IPSDEAction | null {
    if (this.enterpsdeaction != null) return this.enterpsdeaction;
    const value = this.M.getEnterPSDEAction;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.enterpsdeaction = ipsdataentity.findPSDEAction(value);
    }
    return this.enterpsdeaction;
  }

  get enterPSDEAction(): IPSDEAction | null {
    return this.getEnterPSDEAction();
  }

  getEnterPSDEActionMust(): IPSDEAction {
    const value = this.getEnterPSDEAction();
    if (value == null) {
      throw new Error('未指定进入实体行为');
    }
    return value;
  }

  get enterStateMode(): 'ANY' | 'SOME' {
    return this.M.enterStateMode;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get mSTag(): string {
    return this.M.mSTag;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get oPPrivDenyMsg(): string {
    return this.M.oPPrivDenyMsg;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psdemainstateactions: IPSDEMainStateAction[] | null = null;

  getPSDEMainStateActions(): IPSDEMainStateAction[] | null {
    if (this.psdemainstateactions == null) {
      this.psdemainstateactions = this.fillChildListModel(this.M.getPSDEMainStateActions, 'dataentity.mainstate.IPSDEMainStateAction') as IPSDEMainStateAction[];
    }
    return this.psdemainstateactions;
  }

  get psDEMainStateActions(): IPSDEMainStateAction[] | null {
    return this.getPSDEMainStateActions();
  }

  findPSDEMainStateAction(objKey: any): IPSDEMainStateAction | null {
    return this.getPSModel5('dataentity.mainstate.IPSDEMainStateAction', this.getPSDEMainStateActions(), objKey) as IPSDEMainStateAction;
  }

  protected psdemainstatefields: IPSDEMainStateField[] | null = null;

  getPSDEMainStateFields(): IPSDEMainStateField[] | null {
    if (this.psdemainstatefields == null) {
      this.psdemainstatefields = this.fillChildListModel(this.M.getPSDEMainStateFields, 'dataentity.mainstate.IPSDEMainStateField') as IPSDEMainStateField[];
    }
    return this.psdemainstatefields;
  }

  get psDEMainStateFields(): IPSDEMainStateField[] | null {
    return this.getPSDEMainStateFields();
  }

  findPSDEMainStateField(objKey: any): IPSDEMainStateField | null {
    return this.getPSModel5('dataentity.mainstate.IPSDEMainStateField', this.getPSDEMainStateFields(), objKey) as IPSDEMainStateField;
  }

  protected psdemainstateopprivs: IPSDEMainStateOPPriv[] | null = null;

  getPSDEMainStateOPPrivs(): IPSDEMainStateOPPriv[] | null {
    if (this.psdemainstateopprivs == null) {
      this.psdemainstateopprivs = this.fillChildListModel(this.M.getPSDEMainStateOPPrivs, 'dataentity.mainstate.IPSDEMainStateOPPriv') as IPSDEMainStateOPPriv[];
    }
    return this.psdemainstateopprivs;
  }

  get psDEMainStateOPPrivs(): IPSDEMainStateOPPriv[] | null {
    return this.getPSDEMainStateOPPrivs();
  }

  findPSDEMainStateOPPriv(objKey: any): IPSDEMainStateOPPriv | null {
    return this.getPSModel5('dataentity.mainstate.IPSDEMainStateOPPriv', this.getPSDEMainStateOPPrivs(), objKey) as IPSDEMainStateOPPriv;
  }

  protected prevpsdemainstates: IPSDEMainState[] | null = null;

  getPrevPSDEMainStates(): IPSDEMainState[] | null {
    if (this.prevpsdemainstates == null) {
      const value = this.M.getPrevPSDEMainStates;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: IPSDEMainState[] = [];
      const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
      for (let i = 0; i < arrayNode.length; i++) {
        const item = ipsdataentity.findPSDEMainState(arrayNode[i]);
        if (item != null) {
          list.push(item);
        }
      }
      this.prevpsdemainstates = list;
    }
    return this.prevpsdemainstates.length == 0 ? null : this.prevpsdemainstates;
  }

  get prevPSDEMainStates(): IPSDEMainState[] | null {
    return this.getPrevPSDEMainStates();
  }

  findPrevPSDEMainState(objKey: any): IPSDEMainState | null {
    return this.getPSModel5('dataentity.mainstate.IPSDEMainState', this.getPrevPSDEMainStates(), objKey) as IPSDEMainState;
  }

  get state2Value(): string {
    return this.M.state2Value;
  }

  get state3Value(): string {
    return this.M.state3Value;
  }

  get stateValue(): string {
    return this.M.stateValue;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get viewActions(): 1 | 2 | 4 | 8 | 16 | 32 | 64 | 1024 | 128 | 256 | 512 | 2048 {
    return this.M.viewActions;
  }

  get wFStateMode(): 0 | 1 | 2 | 3 {
    return this.M.wFStateMode;
  }

  get actionAllowMode(): boolean {
    return this.M.actionAllowMode;
  }

  get allowMode(): boolean {
    return this.M.allowMode;
  }

  get default(): boolean {
    return this.M.default;
  }

  get enableViewActions(): boolean {
    return this.M.enableViewActions;
  }

  get fieldAllowMode(): boolean {
    return this.M.fieldAllowMode;
  }

  get oPPrivAllowMode(): boolean {
    return this.M.oPPrivAllowMode;
  }

  get cls(): string {
    return 'PSDEMainStateImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.mainstate.IPSDEMainState') return true;
    return super.instanceof(cls);
  }
}
